<template>
  <el-dialog :visible.sync="isShow" width="800px" destroy-on-close @close="close">
    
    <el-descriptions title="提现详情" :column="2" border>
      <el-descriptions-item label="状态">{{ orderStatus[itemModel.orderStatus]}}</el-descriptions-item>
      <el-descriptions-item label="供应商名称">{{ itemModel.allianceModel.name||'' }}</el-descriptions-item>
      <el-descriptions-item label="申请日期">{{ itemModel.createTime }}</el-descriptions-item>
      <el-descriptions-item label="提现金额">{{ itemModel.money }}</el-descriptions-item>
      <el-descriptions-item label="手续费">{{ itemModel.serviceCharge }}</el-descriptions-item>
      <el-descriptions-item label="到账金额">{{ itemModel.realMoney }}</el-descriptions-item>
      <el-descriptions-item label="提现方式">{{ itemModel.payWayAccountModel.types}}</el-descriptions-item>
      <el-descriptions-item label="真实姓名">{{itemModel.payWayAccountModel.realname}}</el-descriptions-item>
    </el-descriptions>
    <el-descriptions :column="3" border>
        <el-descriptions-item label="收款名称">{{itemModel.payWayAccountModel.accountName}}</el-descriptions-item>
        <el-descriptions-item label="收款账号">{{itemModel.payWayAccountModel.account}}</el-descriptions-item>
    </el-descriptions>
    <el-descriptions :column="1" border v-if="itemModel.payWayAccountModel.types!='bank'">
        <el-descriptions-item label="收款码">
            <el-image style="width: 200px;" fit="contain" :src="itemModel.payWayAccountModel.paywayCodeUrl"></el-image>
        </el-descriptions-item>
    </el-descriptions>
    <el-descriptions :column="1" border>
        <el-descriptions-item label="备注（必填）">
            <template>
                <el-form ref="itemForm" :model="itemModel" :rules="rules">
                  <el-form-item prop="remark">
                    <el-input type="textarea" placeholder="请输入" v-model="itemModel.remark" maxlength="225"></el-input>
                  </el-form-item>
                </el-form>
              </template>
        </el-descriptions-item>
    </el-descriptions>
    <div class="bottom">
        <el-button type="primary" @click="confirm('itemForm')" >确认打款</el-button>
        <el-button style="margin-left: 100px" @click="refuse('itemForm')">拒绝打款</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { operateActionPost } from '@/api/interface/operate.js'

export default {
  components: {},
  data() {
    return {
        isShow: false,
        orderId: '',
        itemModel: {allianceModel:{},payWayAccountModel:{}, remark: ''},
        currentDialog: '',
        openshopParams: {},
        rules: {
            remark: [{ required: true, message: '请输入备注', trigger: 'blur' }]
        },
        adminOptions: [],
        orderStatus: {'INITIAL': '初始状态', 'WAIT_SEND': '待打款', 'FINISH': '已发放', 'REFUSE': '已拒绝'},
        typesList: {'ali': '支付宝', 'wx': '微信', 'bank': '银行卡'}
    }
  },
  methods:{
    show(e, currentDialog){
      this.isShow = true
      this.currentDialog = currentDialog
      if(this.currentDialog == 'update'){
        this.orderId = e
        this.findOutMoneyOrderInfo()
      }
    },
    close(){
        this.isShow = false
        Object.assign(this.$data, this.$options.data())
    },
    //确认提现
    confirm(formName){
        this.$refs[formName].validate((valid) => {
        if (valid) {
          operateActionPost('/api/system/walletAllianceRecord/confirmOutMoney/', {
                orderId: this.orderId,
                remark: this.itemModel.remark
            }).then(res=>{
                if(res.data.code == 10000){
                    this.close()
                    this.$emit("confirm")
                    this.$message({
                        message: '操作成功',
                        type: 'success'
                    })
                }
            })
        }
      })
    },
    refuse(formName){
        this.$refs[formName].validate((valid) => {
        if (valid) {
          operateActionPost('/api/system/walletAllianceRecord/refuseOutMoney/', {
                orderId: this.orderId,
                remark: this.itemModel.remark
            }).then(res=>{
                if(res.data.code == 10000){
                    this.close()
                    this.$emit("confirm")
                    this.$message({
                        message: '操作成功',
                        type: 'success'
                    })
                }
            })
        }
      })
    },
    findOutMoneyOrderInfo(){
      operateActionPost('/api/system/walletAllianceRecord/getItemById/', {
        obj_id: this.orderId
      }).then(res => {
        if(res.data.code == 10000){
          this.itemModel = res.data.data
          this.itemModel.createTime = this.itemModel.createTime.slice(0, 19).replace('T', ' ')
        }
      });
    },
  }
}
</script>

<style lang="scss" scoped>
.bottom{
    margin-top: 60px;
    display: flex;
    flex-direction: row;
    justify-content: center;
}
</style>
